<?php
namespace app\demo_record\controller;

use cmf\controller\AdminBaseController;
use app\demo_record\model\RecordModel;


class RecordAdminController extends AdminBaseController
{
    public function showList()
    {
        $model=new RecordModel();
        $list=$model->db()->paginate(20);
        $page=$list->render();
        $is_check_arr=[
            "0"=>"未审核",
            "1"=>"通过",
            "2"=>"拒绝",
        ];
        foreach($list as $index => $item){
            $item["is_check_str"] = isset($is_check_arr[$item["is_check"]]) ? $is_check_arr[$item["is_check"]] : "";
            $item["create_time_str"]=date("Y-m-d H:i:s",$item["create_time"]);
            $item["update_time_str"]=date("Y-m-d H:i:s",$item["update_time"]);
        }
        $this->assign("list",$list);
        $this->assign("page",$page);
        return $this->fetch("list");
    }
    public function updateCheckStatus()
    {
        $id=input("id");
        $is_check=input("is_check");
        $model=new RecordModel();
        $result=$model->db()->where("id = $id")->setField("is_check",$is_check);
        if(!$result){
            $this->error($model->getError());
        }
        $this->success("更新成功");
    }
    public function deleteItem()
    {
        $id=input("id","");
        if( $id==="" ){
            $this->error("记录编号不能为空");
        }
        $count=RecordModel::destroy($id);
        if(!$count){
            $this->error("删除失败");
        }
        $this->success("操作成功");
    }
}
